import type { IColumnsOption } from 'vc';
import { INDEX, COMPANY_NAME, BUSINESS_DATA, REGISTERED_CAPITAL, PROVINCE, CITY, COUNTRY, INDUSTRY_CATEGORY } from '@/utils/tableColumn';
import { setHrefUrlTool } from '@/utils';

export function useTable() {
  const columns = ref<IColumnsOption[]>([
    { ...INDEX },
    { ...COMPANY_NAME },
    {
      field: 'noticeDate',
      title: '披露日期',
      align: 'center',
      // sort: 'desc',
      sortable: true,
      width: 110,
      sortBy: 'noticeDate'
    },
    {
      width: 160,
      field: 'attachments',
      title: '信息来源',
      slots: {
        default: ({ row }) => {
          return (
            <div>
              <a onClick={() => setHrefUrlTool(row.fileType, row.fileUrl)}>查看</a>
              <br />
            </div>
          );
        }
      }
    },
    {
      field: 'statisticalYear',
      title: '纳入年度',
      align: 'center',
      // sort: 'desc',
      sortable: true,
      width: 110,
      sortBy: 'statisticalYear'
    },
    {
      field: 'companyType',
      title: '所属类别',
      align: 'center',
      // sort: 'desc',
      sortable: true,
      sortBy: 'companyType',
      width: 200,
      formatter: ({ row }) => {
        return row.companyType ? row.companyType : '-';
      }
    },
    {
      field: 'liabilityLimit',
      title: '最低责任险额',
      align: 'center',
      // sort: 'desc',
      sortable: true,
      sortBy: 'liabilityLimit',
      width: 110
    },
    {
      field: 'certificateAuthority',
      title: '认定单位',
      // sort: 'desc',
      sortable: true,
      sortBy: 'certificateAuthority',
      width: 200
    },
    { ...PROVINCE },
    { ...CITY },
    { ...INDUSTRY_CATEGORY },
    { ...BUSINESS_DATA },
    { ...REGISTERED_CAPITAL }
  ]);

  // 变更弹窗
  const showPermitChangesDetail = ref(false);
  const permitChangesDetails = ref([]);

  const permitChangesDetailFn = (data) => {
    console.log(data);
    showPermitChangesDetail.value = true;
    permitChangesDetails.value = data;
  };

  return {
    columns
  };
}
